home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 73700.776@compuserve.com (Walter C. Riley)
- Newsgroups: comp.lang.c++
- Subject: Re: Output precision
- Date: Sat, 27 Jan 1996 13:51:04 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4edamo$fil@dub-news-svc-2.compuserve.com>
- References: <rplDLKLwK.119@netcom.com>
- NNTP-Posting-Host: ad60-032.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- rpl@netcom.com (Robert Laudati) wrote:
-
- >It doesn't get too much more basic than this, but I can not
- >set the precision correctly on output. Here's the sample:
-
- >#include <stdio.h>
- >#include <iostream.h>
- >#include <iomanip.h>
- >
- >int main( int argc, char *argv[])
- >{
- > int i=0;
- > float x=56.0;
- > double y=34.038383999;
- >
- > i = cout.precision(6);
- > printf( "%d %f %lf\n\n", i, x, y );
- > cout << i << " " << x << " " << y << endl;
- > return 0;
- >}
-
- >Which results in:
-
- >robl@cosmo<216>: test
- >6 56.000000 34.038384
- >
- >6 56 34.0384
- >robl@cosmo<217>:
-
- >I'm running gcc 2.7.1 on Solaris 2.4 - and very confused!
-
-
- Rob,
-
- If you are trying to match the printf output exactly, I can't help
- you. You can use cout.setf(ios::showpoint) to force the decimal on
- the 56, but I don't know of a simple way to force 6 zeros after the
- decimal using built-in mainipulators. Hopefully someone that does
- will jump in. Perhaps ios::precision(int) might better have been
- named significant_digits.
-
- You can also use the manipulators setiosflags and resetiosflags to
- change the flags between the variables in the stream output statement
- --on the fly, so to speak. I only mention it because you included
- iomanip.h but didn't use manipulators.
-
- Good luck,
- Walt
-
-
-